<template>
	<view class="content">
		<view class="header">
			<view class="seting" :style="{ top: (statusBarHeight ) + 'px' }">
				<image src="/static/images/menu/set.png" mode="" @click="setingClick"></image>
			</view>
			<view class="statusBar" :style="{ height: statusBarHeight + 'PX'}"></view>
			<view class="userInfo" @click="userInfoClick">
				<view class="pic">
					<image :src="'/static/images/picture/' + userInfo.user_portrait" mode=""></image>
				</view>
				<view class="info">
					<view class="name">
						<text>{{ userInfo.user_nick_name }}</text>
						<image src="../../static/images/svip.png" mode="" class="vipImg" v-if="userInfo.group_id !== 0"></image>
					</view>
					<view class="endTime" v-if="userInfo.group_id == 3">
						到期时间：<text style="color: #FF6022">{{ userInfo.user_end_time | timeForm }}</text>
					</view>
					<view class="endTime" v-if="userInfo.group_id !== 3">
						状态：<text style="color: #FF6022">{{ vipList[userInfo.group_id] }}</text>
					</view>
					<text style="font-size: 13px;">签名：{{ userInfo.user_portrait_thumb? userInfo.user_portrait_thumb: '矩龙不倒，陪你到老'}}</text>
				</view>
			</view>
			
			<view class="videoStorage" >
				<view class="title" @click="titleClick">
					<text style="margin-left: 20rpx;font-weight: bold;color:#000;">观看历史</text>
					<text style="margin-right: 20rpx;color: #ccc;font-size: 12px;">更多 ></text>
				</view>
				<text v-if="videoStorage.length == 0" style="color: #000; text-align: center;line-height: 200rpx;">空空如也，赶紧看点吧！</text>
				<view class="videoitem" v-show="videoStorage.length !== 0">
					<scroll-view :scroll-x="true"  :style="{ width: videoStorageWidth + 'px'}" >
						<view class="item" v-for="(item, index) in videoStorage" :key="index" @click="videoStorageClick(item)">
							<view class="img">
								<image :src="item.vod_pic" mode=""></image>
								<text>{{((item.vod_currentTime / item.vod_duration) * 100).toFixed(0)}}%</text>
							</view>
							<text>{{ item.vod_name }}</text>
						</view>
					</scroll-view>
						
				
				</view>
			</view>
		</view>
		
		<view class="tool" :style="{ marginTop: toolTop + 'px'}">
			<view class="toolTitle">
				常用功能
			</view>
			<view class="menu">
				<view class="menuItem" v-for="(menu, index) in menuList" :key="index" @click="menuClick(index, menu.name)">
					<image :src="'/static/images/menu/' + menu.img" mode=""></image>
					<text>{{ menu.name }}</text>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import { select } from '@/commons/querySelect.js'
	import { getLocalTime } from '@/commons/utiles.js'
	export default {
		data() {
			return {
				statusBarHeight: this.$systemInfo.statusBarHeight,
				currentTime: 0,
				videoStorageWidth: 0,
				toolTop: 0,
				videoStorage: [],
				loginStatus: false,
				userInfo: {
					user_name: '你好，请登录',
					user_id: 0,
					user_pwd: '',
					group_id: 0,
					user_nick_name: '你好，请登录',
					user_status: 0,
					user_portrait: 'boy_1.png',
					user_end_time: (new Date().getTime() / 1000).toFixed(0),
					user_portrait_thumb: ''
					 
				},
				vipList: ['游客', '游客', '已到期','vip会员'],
				menuList: [
					{ name: '账号管理', img: 'accountmanagement.png'},
					{ name: '观看记录', img: 'record.png'},
					{ name: '我的收藏', img: 'collect.png'},
					{ name: '公告通知', img: 'announcement.png'},
					{ name: '意见反馈', img: 'feedback2.png'},
					{ name: '分享', img: 'share.png'},
					{ name: '联系客服', img: 'service.png'},
					{ name: '设置中心', img: 'Settings.png'},
					{ name: '关于我们', img: 'gy.png'},
				]
			};
		},
		filters: {
			formatTime(val) {
				return getLocalTime(val)
			}
		},
		onLoad() {
			this.getVideoStroage()
		},
		onShow() {
			this.getVideoStroage()
			if (getApp().globalData.loginStatus) {
				this.loginStatus = getApp().globalData.loginStatus
				this.userInfo = getApp().globalData.userInfo
			} else {
				this.loginStatus = getApp().globalData.loginStatus
				this.userInfo = {
					user_name: '你好，请登录',
					user_id: 0,
					user_pwd: '',
					group_id: 0,
					user_nick_name: '你好，请登录',
					user_status: 0,
					user_portrait: 'boy_1.png',
					user_portrait_thumb: ''
					 
				}
			}
		},
		async mounted() {
			const videoStorage = await select('.videoStorage')
			this.videoStorageWidth = videoStorage.width - uni.upx2px(10)
			const time = new Date()
			this.currentTime = parseInt(time.getTime() / 1000)
			this.toolTop = videoStorage.height / 2 + 20
		},
		methods: {
			getVideoStroage() {
				const videoStorage = uni.getStorageSync('videoCache') || []
				this.videoStorage = videoStorage.splice(0, 6)
			},
			titleClick() {
				this.$goto('/pages/record/record')
			},
			async videoStorageClick(item) {
				const { data: res } = await this.$http({
					url: this.$api.search,
					data: {
						vod_id: Number(item.vod_id)
					}
				})
				if (res.status !== 200) {
					uni.showToast({
						title: '资源有误，赶紧找我聊聊',
						icon: 'error'
					})
					return 
				}
				this.$goto('/pages/player/player', res.data.result[0])
			},
			menuClick(index, name) {
				switch(index) {
					case 0: 
						this.$goto('/pages/user/user')
					break
					case 1:
						this.$goto('/pages/record/record')
					break
					case 2:
						
					break
					case 3:
						this.$goto('/pages/inform/inform')
					break
					case 4:
						this.$goto('/pages/feedback/feedback')
					break
					case 5:
					
					break
					case 6:
					
					break
					case 7:
						this.$goto('/pages/seting/seting')
					break
					case 8:
						this.$goto('/pages/about/about')
					break
					default: 
					
					break
				}
			},
			// 账号管理
			userInfoClick() {
				if (!this.loginStatus) {
					this.$goto('/pages/login/login')
					return
				}
				this.$goto('/pages/user/user')
			},
			// 设置中心
			setingClick() {
				this.$goto('/pages/seting/seting')
			}
		}
	}
</script>

<style lang="scss" lang="scss">
	.content {
		width: 100%;
		height: 100%;
		background-color: #f7f8fa;
	}
	.header {
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		height: 450rpx;
		background-image: linear-gradient( 135deg, #90F7EC 10%, #32CCBC 100%);
		color: #fff;
		border-bottom-left-radius: 100rpx;
		border-bottom-right-radius: 100rpx;
		box-sizing: border-box;
		
		.seting {
			position: absolute;
			right: 30rpx;
			width: 50rpx;
			height: 50rpx;
			
			image {
				width: 100%;
				height: 100%;
			}
		}
		
		.userInfo {
			display: flex;
			width: 90%;
			height: 200rpx;
			margin-top: 20rpx;
			.pic {
				width: 200rpx;
				height: 200rpx;
				padding: 2rpx;
				border: 5px solid #fff;
				border-radius: 100px;
				box-sizing: border-box;
				
				image {
					width: 100%;
					height: 100%;
					border-radius: 100px;
				}
			}
			
			.info {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				margin-left: 30rpx;
				box-sizing: border-box;
				
				.name {
					display: flex;
					align-items: center;
					height: 80rpx;
					text {
						line-height: 80rpx;
						font-size: 40rpx;
					}
				}
				
				.vipImg {
					margin-left: 15rpx;
					width: 80px;
					height: 30px;
				}
				
				.endTime {
					font-size: 12px;
				}
			}
		}
	}
	
	.videoStorage {
		display: flex;
		flex-direction: column;
		position: absolute;
		left: 50%;
		bottom: 0;
		width: 94%;
		height: 300rpx;
		background-color: #fff;
		border-radius: 10rpx;
		transform: translate(-50%, 50%);
		
		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;
			height: 80rpx;
			box-sizing: border-box;
		}
		
		scroll-view {
			flex: 1;
			display: flex;
			flex-direction: row;
			flex-wrap: nowrap;
			white-space: nowrap;
			padding: 10rpx;
			box-sizing: border-box;
			
			
			.item {
				display: inline-flex;
				flex-direction: column;
				width: 250rpx;
				height: 100%;
				margin-right: 10rpx;
				.img {
					position: relative;
					image {
						width: 250rpx;
						height: 160rpx;
						
						border-radius: 10rpx;
					}
					text {
						position: absolute;
						right: 10rpx;
						bottom: 15rpx;
						width: 80rpx;
						height: 40rpx;
						background-color: rgba(50, 204, 188, .8);
						border-radius: 5rpx;
						font-size: 12px;
						color: #fff;
					}
				}
				
				text {
					width: 250rpx;
					height: 40rpx;
					text-align: center;
					line-height: 40rpx;
					font-size: 12px;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
					overflow: hidden;
					color: #706b6f;
				}
			}
		}
	}
	
	.tool {
		display: flex;
		flex-direction: column;
		width: 94%;
		height: 500rpx;
		margin: 0 auto;
		background-color: #fff;
		border-radius: 10rpx;
		
		.toolTitle {
			width: 100%;
			height: 80rpx;
			padding: 0 30rpx;
			line-height: 80rpx;
			font-weight: bold;
			box-sizing: border-box;
			
		}
		
		.menu {
			flex: 1;
			display: flex;
			// justify-content: center;
			// align-items: center;
			flex-wrap: wrap;
			
			.menuItem {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				width: calc(100% / 3);
				height: calc(400rpx / 3);
				font-size: 13px;
				box-sizing: border-box;
				
				image {
					width: 32px;
					height: 32px;
					margin-bottom: 8rpx;
					
				}
				text {
					text-shadow: 4px 4px 4px #ccc;
				}
			}
		}
	}
</style>
